package edu.protbioinfo;

public class AminoAcid {
	private String name;
	private char letter;
	private String abbreviation;

	private static final AminoAcid[] aminoAcids = new AminoAcid[]{
		new AminoAcid("Alanine", "Ala", 'A'),
		new AminoAcid("Arginine", "Arg", 'R'),
		new AminoAcid("Asparagine", "Asn", 'N'),
		new AminoAcid("Aspartic acid", "Asp", 'D'),
		new AminoAcid("Cysteine", "Cys", 'C'),
		new AminoAcid("Glutamic acid", "Glu", 'E'),
		new AminoAcid("Glutamine", "Gln", 'Q'),
		new AminoAcid("Glycine", "Gly", 'G'),
		new AminoAcid("Histidine", "His", 'H'),
		new AminoAcid("Isoleucine", "Ile", 'I'),
		new AminoAcid("Leucine", "Leu", 'L'),
		new AminoAcid("Lysine", "Lys", 'K'),
		new AminoAcid("Methionine", "Met", 'M'),
		new AminoAcid("Phenylalanine", "Phe", 'F'),
		new AminoAcid("Proline", "Pro", 'P'),
		new AminoAcid("Serine", "Ser", 'S'),
		new AminoAcid("Threonine", "Thr", 'T'),
		new AminoAcid("Tryptophan", "Trp", 'W'),
		new AminoAcid("Tyrosine", "Tyr", 'Y'),
		new AminoAcid("Valine", "Val", 'V')
	};  
	
	private AminoAcid(String name, String abbreviation, char letter) {
		this.name = name;
		this.letter = letter;
		this.abbreviation = abbreviation;
	}

	public String getName() {
		return name;
	}

	public char getLetter() {
		return letter;
	}

	public String getAbbreviation() {
		return abbreviation;
	}

	public static AminoAcid elementByName(String name){
		for(AminoAcid aa : aminoAcids){
			if(aa.name.equals(name)){
				return aa;
			}
		}
		return null;
	}
	
	public static AminoAcid elementByAbbr(String abbr){
		for(AminoAcid aa : aminoAcids){
			if(aa.abbreviation.equals(abbr)){
				return aa;
			}
		}
		return null;
		
	}
	
	public static AminoAcid elementByLetter(char letter){
		for(AminoAcid aa : aminoAcids){
			if(aa.letter == letter){
				return aa;
			}
		}
		return null;
	}
	
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AminoAcid other = (AminoAcid) obj;
		return name.equals(other.name) || abbreviation.equals(other.abbreviation) || letter == other.letter;
	}
	
	
}
